package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.admin.biz.AdminExamBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminExamPageResp;
import com.wcs.exam.controller.admin.resp.AdminExamViewResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-考试
 *
 * @author wcs
 * @since 2025-03-13
 */
@Tag(name = "Admin-考试")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/exam")
public class AdminExamController {

    @NotNull
    private final AdminExamBiz biz;

    @Operation(summary = "考试-分页")
    @OptLog(value = "考试-分页")
    @GetMapping(value = "/page")
    public Result<Page<AdminExamPageResp>> page(@ModelAttribute AdminExamPageReq req) {
        return biz.page(req);
    }

    @Operation(summary = "考试-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLogCache
    @GetMapping(value = "/view")
    public Result<AdminExamViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "考试-编辑发布状态")
    @OptLog(value = "考试-编辑发布状态")
    @PutMapping(value = "/edit/publish/status")
    public Result<String> editPublishStatus(@RequestBody @Valid AdminExamEditPublishStatusReq req) {
        return biz.editPublishStatus(req);
    }

    @Operation(summary = "考试-排序")
    @OptLog(value = "考试-排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminExamSortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "考试-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLog(value = "考试-删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }

    /*---------------------------------------------------- 模拟考试 ----------------------------------------------------*/

    @Operation(summary = "模拟考试-添加")
    @OptLog(value = "模拟考试-添加")
    @PostMapping(value = "/save/mock")
    public Result<String> saveMock(@RequestBody @Valid AdminExamMockSaveReq req) {
        return biz.saveMock(req);
    }

    @Operation(summary = "模拟考试-编辑")
    @OptLog(value = "模拟考试编辑", isUpdate = true)
    @PutMapping(value = "/edit/mock")
    public Result<String> editMock(@RequestBody @Valid AdminExamMockEditReq req) {
        return biz.editMock(req);
    }

    /*---------------------------------------------------- 报名考试 ----------------------------------------------------*/

    @Operation(summary = "报名考试-添加")
    @OptLog(value = "报名考试添加")
    @PostMapping(value = "/save/registration")
    public Result<String> saveRegistration(@RequestBody @Valid AdminExamRegistrationSaveReq req) {
        return biz.saveRegistration(req);
    }

    @Operation(summary = "报名考试-编辑")
    @OptLog(value = "报名考试编辑", isUpdate = true)
    @PutMapping(value = "/edit/registration")
    public Result<String> editRegistration(@RequestBody @Valid AdminExamRegistrationEditReq req) {
        return biz.editRegistration(req);
    }

    @Operation(summary = "报名考试-报名/开考延期", description = "只有正式考试，开考前才能进行延期")
    @OptLog(value = "报名考试-报名/开考延期")
    @PutMapping(value = "/postponement")
    public Result<String> postponement(@RequestBody @Valid AdminExamRegistrationPostponementReq req) {
        return biz.postponement(req);
    }

    @Operation(summary = "报名考试-延迟交卷-批量设置")
    @PutMapping(value = "/submit/late/batch")
    public Result<String> submitLateBatch(@RequestBody @Valid AdminExamRegistrationSubmitLateBatchReq req) {
        return biz.submitLateBatch(req);
    }
}
